//
//  NBMessageTableViewController.swift
//  NBSinaWeibo
//
//  Created by ac on 16/5/19.
//  Copyright © 2016年 ac. All rights reserved.
//

import UIKit

class NBMessageTableViewController: NBBaseTableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        loginView.updateUI("visitordiscover_image_message", lblText: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "show", target: self, action: #selector(changeBadgeValue))
        tabBarItem.badgeValue = "10"
        setBackground()
    }
    
    @objc private func changeBadgeValue(){
        tabBarItem.badgeValue = nil
        tabBarItem.badgeValue = "\(random()%100)"
    }
    
    private func setBackground() {
        for subview in self.tabBarController!.tabBar.subviews{
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                for v in subview.subviews {
                    if v.isKindOfClass(NSClassFromString("_UIBadgeView")!) {
                        for bgView in v.subviews {
                            if bgView.isKindOfClass(NSClassFromString("_UIBadgeBackground")!) {
                                print(bgView,"终于找到你,还好没放弃")
                                
                                
                                let image = UIImage(named: "main_badge")
                                //调用 _UIBadgeBackground类型的对象的KVC方法 简介设置值
                                bgView.setValue(image, forKey: "_image")
                            }
                        }
                    }
                }
            }
        }
    }
    


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }


}
